<template>
	<view>
		<view id="web-info" style="width: 100%;height:100%;">
			<web-view style="width: 100%;height:50%;"  :src="pdfUrl"></web-view>
			<!-- <object  :src="pdfUrl"  width="100%" height="100%"></object> -->
			<!-- <iframe
				    :src="pdfUrl"
				    type="application/x-google-chrome-pdf"
				    width="100%"
				    height="100%" /> -->
			<!-- <embed :src="pdfUrl" type="application/pdf" width="90%" height="700px"/> -->
		</view>
	</view>
</template>

<script>
	export default {
		name: 'viewPdf',
		data() {
			return {
				htmlUrl: '/hybrid/html/web/viewer.html', 
				isShow: true,
				pdfUrl: '',
				env: '',
				pptList:[],
				detailId:'',
			}
		},

		onLoad(params) {
			let option = decodeURIComponent(params.pdfUrl);
			let fileUrl = this.$url + option
			this.detailId = params.detailId
			console.log(params,111111)
			// this.pdfUrl = fileUrl
			// this.getFile2(fileUrl)
			this.getData(params.id)
		},
		methods: {
			//根据ppt的id
			gotoppt(detailId){
			  this.detailId = detailId
			  console.log(this.pptList,6666)
			  this.pptList.forEach((item,index)=>{
			    if(item.educationDoc.id == detailId){
			      //赋值ppt链接
			      this.pdfUrl = this.$url + item.educationDoc.fileUrl
				  this.pdfUrl= this.htmlUrl+ '?file=' + this.pdfUrl
				  console.log(this.pdfUrl,2222)
			    }
			  })
			},
			getData(id) {
				let that = this;
				this.$http.get("/f/course?id="+id)
					.then(function(response) {
						console.log(response.data,999)
						let data = Object.assign(response.data.course,response.data.course.courseInfo)
						that.pptList = data.educationCoursePptDetailsList;
						that.gotoppt(that.detailId)
						uni.hideLoading();
					})
					.catch(function(error) {
						console.log(error);
					})
			},
			getFile2(data) {
				let that = this;
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				uni.downloadFile({
					url: data,
					header: {
						'Accept': 'application/json',
						'Content-Type': 'application/json',
					},
					success: (result) => {
						var tempFilePath = result.tempFilePath
						//这里的`/hybrid/html/web/viewer.html`是pdf.js放在项目里的地址
						//h5页面这样写即可
						that.pdfUrl = `/hybrid/html/web/viewer.html?file=${tempFilePath}`;
						//app需要特殊处理一下才行
						// let fileUrl = plus.io.convertLocalFileSystemURL(tempFilePath)
						// that.pdfUrl = `/hybrid/html/web/viewer.html?file=${fileUrl}`;
						uni.hideLoading();
					},
					fail: function(res) {
						uni.hideLoading();
						uni.showToast({
							title: '文件下载失败，请重试',
							icon: "none",
							mask: true,
							position: "center"
						})
					},
				})
			},
		}
	}
</script>
<style lang="scss" scoped>
	#web-info {
		width: 100%;
		height: 50%;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>
